import Editor from "../editor"

import { Operation } from "./baseOperation"

import type { Selection } from "../models/selectionModel"

export class SetSelectionOperation extends Operation {
  public type: string = "SetSelectionOperation"
  constructor(public selection_: Selection) {
    super()
  }

  apply(editor: Editor) {
    editor.getSelectionModel()?.setSelection(this.selection_)
  }

  reverse(): Operation[] {
    return [
      new SetSelectionOperation({
        anchor: this.selection_?.anchor || 0,
        focus: this.selection_?.focus || 0,
      }),
    ]
  }
}
export default SetSelectionOperation
